02 Jun 2020

What is git?

“You use Git to take snapshots of all the files in a folder.”

Alice Bartlett


Snapshots in time

Snapshots in time

Three key concepts


  • Repository - your project folder
  • Commit - a snapshot of your folder
  • Branch - a working version of your folder

Three key concepts


  • Repository - your project folder
  • Commit - a snapshot of your folder
    • We use push to send the snapshots online
    • And pull to retrieve an updated snapshot
  • Branch - a working version of your folder

Work git!

Work git!

Work git!

Work git!

Work git!

Work git!

Work git!

Work git!

Work git!

Work git!

Work git!

Work git!

Work git!

Installing git


  • For Windows, download the executable here
  • On a mac type git --version in your terminal
  • On linux machines type sudo apt install git-all in your terminal


Note that you may need admin rights on your computer, without these you’ll need to request an install.

Create a GitHub account


GitHub offers a range of account types. A free account is available for organisations and individuals.

Even if you’re in an institution, create a personal GitHub account to keep track of you own work.

You’ll find more information, and links for creating an account, here.

Create a repository

  • Follow the instructions here to create your first repository

  • Some key files to include:

    README - ideally format this as a markdown md file (more info here and here)

    LICENSE - how you want people to re-use your code (info)

    .gitignore - names of any files in your project you don’t want on GitHub (templates)

Linking to RStudio



  • Rstudio does a lot of the hard work for you
  • You can use the terminal, if you like
  • Here are some screenshots showing you how to link a GitHub repository to RStudio

git the most out of GitHub


  • Manage your work on a project using the Projects tab
  • Track your tasks using issues
  • Use your README to describe your project (more info here and here)
  • Document your project using a wiki
  • Host a website on GitHub, check out these jekyl themes

Useful resources

  • Introduction to GitHub presentation (slides and video)
  • All you need to know about GitHub in their help pages
  • Detailed book about git, GitHub and R (here)
  • Detailed overview of RStudio, git and GitHub (here)
  • A game to help us think about git branches (here)
  • ONS GitHub introductory course (here)

git glossary

Command Definition
git status Check current status of local repository - is it up to date?
git branch List existing branches
git branch [branchName] Create new branch
git branch -d [branchName] Delete branch
git checkout [branchName] Switch to branch
git push -u [branchName] Push a branch online
git add [FileName] Stage file for committing
git commit -m [message] Commit staged changes to GitHub. Always add meaningful message.
git push Push committed changes to GitHub
git pull Pull changes from GitHub to local repository
git rm [fileName] Remove file and record
git mv [fileName] Move file and version history within repository